package com.jiantong.work.impl.service;

import com.google.common.base.Throwables;
import com.jiantong.work.impl.manager.RetailBreedRecordManager;
import com.jiantong.work.model.RetailBreedRecord;
import com.jiantong.work.service.RetailBreedRecordWriteService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by mz on 25/7/17.
 *
 */
@Slf4j
@Service
@RpcProvider
public class RetailBreedRecordWriteServiceImpl implements RetailBreedRecordWriteService{

    private final RetailBreedRecordManager retailBreedRecordManager;

    @Autowired
    public RetailBreedRecordWriteServiceImpl(RetailBreedRecordManager retailBreedRecordManager) {
        this.retailBreedRecordManager = retailBreedRecordManager;
    }

    @Override
    public Response<Long> create(RetailBreedRecord retailBreedRecord, Integer toStatus) {
        try{
            return Response.ok(retailBreedRecordManager.create(retailBreedRecord,toStatus));
        }catch (Exception e){
            log.error("failed to create retail breed record case = {}", Throwables.getStackTraceAsString(e));
            return Response.fail("failed to create retail breed record");
        }
    }

    @Override
    public Response<Boolean> update(RetailBreedRecord retailBreedRecord, Integer toStatus) {
        try{
            return Response.ok(retailBreedRecordManager.update(retailBreedRecord,toStatus));
        }catch (Exception e){
            log.error("failed to update retail breed record case = {}",Throwables.getStackTraceAsString(e));
            return Response.fail("failed to update retail breed record");
        }
    }

}
